﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" 
	AutoEventWireup="true"
	CodeFile="Dashboard.aspx.cs" 
	Inherits="Dashboard" 
	Title="Панель управления -- Система запуска задач" %>

<%@ Import Namespace="Progresoft.Common" %>
<%@ Import Namespace="Progresoft.Scheduler.RemoteInterface.Api" %>

<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" runat="Server">
	<div class="timeTasks">
		<div class="schedulerHeader">
			<div>Задачи по расписанию или запущенные вручную</div>
		</div>
		<div class="schedulerTable">
			<asp:ListView runat="server" ID="rptScheduledTasks"
				ItemPlaceholderID="placeHolder"
				onitemcommand="rptScheduledTasks_ItemCommand">
				<LayoutTemplate>
					<table width="100%" cellpadding="0" cellspacing="2">
						<col style="width:60px;" align="center" />
						<col style="width:auto;" />
						<col style="width:20%;" align="center" />
						<col style="width:20%;" align="center" />
						<col style="width:60px;" align="center" />
						<col style="width:60px;" align="center" />
						<tr>
							<th>Статус</th>
							<th>Название задачи</th>
							<th>Последний запуск</th>
							<th>Успешно завершен</th>
							<th>Лог</th>
							<th>Запуск</th>
						</tr>
						<tr id="placeHolder" runat="server"></tr>
					</table>
				</LayoutTemplate>
				<ItemTemplate>
					<tr class="<%# GetScheduledTaskRowCss(((ScheduledTaskHealth)Container.DataItem).Status) %>">
						<td>
							<asp:Image runat="server" 
								ImageUrl="<%# GetScheduledTaskStatusIcon(((ScheduledTaskHealth)Container.DataItem).Status) %>"
								ToolTip="<%# EnumHelper.GetValueName<ScheduledTaskStatus>(((ScheduledTaskHealth)Container.DataItem).Status) %>" />
						</td>
						<td>
							<asp:HyperLink ID="lnkTaskInfo" runat="server"
								Text='<%# ((ScheduledTaskHealth)Container.DataItem).TaskName %>'
								NavigateUrl='<%# string.Format("~/TaskInfo.aspx?task={0}&system={1}", Eval("Key"), Eval("SystemName")) %>' />
						</td>
						<td>
							<%# FormatLastStart(((ScheduledTaskHealth)Container.DataItem).StartDate) %>
						</td>
						<td>
							<%# FormatLastSuccessfull(((ScheduledTaskHealth)Container.DataItem).SuccessfullyFinishedAt) %>
						</td>
						<td>
							&nbsp;<asp:HyperLink runat="server" ImageUrl="~/Images/scheduler/view_log.gif" 
								ToolTip="Посмотреть лог"
								Visible="<%#((ScheduledTaskHealth)Container.DataItem).LogID.HasValue %>" 
								NavigateUrl='<%# string.Format("~/ViewLog.aspx?type=scheduled&log={0}&system={1}", Eval("LogID"), Eval("SystemName")) %>' />
						</td>
						<td>
							<asp:ImageButton ID="lnkStart" runat="server" ImageUrl="~/Images/scheduler/action_start.gif" 
								ToolTip="Запустить задачу"
								Visible="<%#!((ScheduledTaskHealth)Container.DataItem).CanStop %>"
								CommandArgument='<%# string.Format("{0},{1}", Eval("Key"), Eval("SystemName")) %>'
								CommandName="StartTask"
								OnClientClick="return confirm('Вы уверены, что хотите запустить задачу вручную?')"
								/>								
							<asp:ImageButton ID="lnkStop" runat="server" ImageUrl="~/Images/scheduler/action_stop.gif" 
								ToolTip="Остановить задачу"
								Visible="<%#((ScheduledTaskHealth)Container.DataItem).CanStop %>"
								CommandArgument='<%# string.Format("{0},{1}", Eval("Key"), Eval("SystemName")) %>'
								CommandName="StopTask"
								OnClientClick="return confirm('Вы уверены, что хотите остановить выполнение задачи?')"
								/>
						</td>
					</tr>
				</ItemTemplate>
			</asp:ListView>
		</div>
	</div>
	<div class="periodicTasks">
		<div class="schedulerHeader">
			<div>Периодические задачи</div>
		</div>
		<div class="schedulerTable">
			<asp:Repeater runat="server" ID="rptPeriodicTasks">
				<HeaderTemplate>
					<table width="100%" cellpadding="0" cellspacing="2">
						<col style="width:60px;" align="center" />
						<col style="width:auto;" />
						<col style="width:20%;" align="center" />
						<col style="width:20%;" align="center" />
						<col style="width:60px;" align="center" />
						<tr>
							<th>Статус</th>
							<th>Название задачи</th>
							<th>Период запуска</th>
							<th>Последний успешный запуск</th>
							<th>Лог</th>
						</tr>
				</HeaderTemplate>
				<ItemTemplate>
					<tr class="<%# GetPeriodicTaskRowCss(((PeriodicTaskHealth)Container.DataItem).Status) %>">
						<td>
							<asp:Image ID="imgPeriodicStatus" runat="server" 
								ImageUrl="<%# GetPeriodicTaskStatusIcon(((PeriodicTaskHealth)Container.DataItem).Status) %>"
								ToolTip="<%# EnumHelper.GetValueName<PeriodicTaskStatus>(((PeriodicTaskHealth)Container.DataItem).Status) %>" />
						</td>
						<td>
							<%# ((PeriodicTaskHealth)Container.DataItem).TaskName %>
						</td>
						<td>
							<%# FormatPeriod(((PeriodicTaskHealth)Container.DataItem).Period)%>
						</td>
						<td>
							<%# FormatLastSuccessfull(((PeriodicTaskHealth)Container.DataItem).SuccessfullyFinishedAt) %>
						</td>
						<td>
							&nbsp;<asp:HyperLink ID="hlViewLog" runat="server" ImageUrl="~/Images/scheduler/view_log.gif" ToolTip="Посмотреть лог"
								NavigateUrl='<%# string.Format("~/ViewLog.aspx?type=periodic&log={0}&system={1}", Eval("LogID"), Eval("System")) %>' />
						</td>
					</tr>
				</ItemTemplate>
				<FooterTemplate>
					</table>
				</FooterTemplate>
			</asp:Repeater>
		</div>
	</div>
</asp:Content>
